<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>isBetween() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>isBetween()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>isBetween()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/query/is-between/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/05-query/06-is-between.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">//&#x4ECE; 2.13.0 &#x5F00;&#x59CB;
moment().isBetween(moment-like, moment-like);
moment().isBetween(moment-like, moment-like, String);
moment().isBetween(moment-like, moment-like, String, String);
// &#x5176;&#x4E2D; moment-like &#x662F; Moment|String|Number|Date|Array

//2.9.0 &#x81F3; 2.12.0
moment().isBetween(moment-like, moment-like);
moment().isBetween(moment-like, moment-like, String);
// &#x5176;&#x4E2D; moment-like &#x662F; is Moment|String|Number|Date|Array
</code></pre>

							</div>
<p>&#x68C0;&#x67E5;&#x4E00;&#x4E2A; moment &#x662F;&#x5426;&#x5728;&#x5176;&#x4ED6;&#x4E24;&#x4E2A; moment &#x4E4B;&#x95F4;&#xFF0C;&#x53EF;&#x9009;&#x5730;&#x68C0;&#x67E5;&#x6307;&#x5B9A;&#x7684;&#x5355;&#x4F4D;&#x523B;&#x5EA6;&#xFF08;&#x5206;&#x949F;&#xFF0C;&#x5C0F;&#x65F6;&#xFF0C;&#x65E5;&#x671F;&#x7B49;&#xFF09;&#x3002;
&#x8FD9;&#x4E2A;&#x5339;&#x914D;&#x662F;&#x6392;&#x4ED6;&#x7684;&#x3002;
&#x524D;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x4F1A;&#x88AB;&#x89E3;&#x6790;&#x4E3A; moment&#xFF08;&#x5982;&#x679C;&#x5C1A;&#x672A;&#x89E3;&#x6790;&#xFF09;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isBetween(&apos;2010-10-19&apos;, &apos;2010-10-25&apos;); // true
moment(&apos;2010-10-20&apos;).isBetween(&apos;2010-10-19&apos;, undefined); // true, &#x56E0;&#x4E3A; moment(undefined) &#x7B49;&#x6548;&#x4E8E; moment()
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x5C06;&#x7C92;&#x5EA6;&#x9650;&#x5236;&#x4E3A;&#x6BEB;&#x79D2;&#x4EE5;&#x5916;&#x7684;&#x5355;&#x4F4D;&#xFF0C;&#x5219;&#x5C06;&#x5355;&#x4F4D;&#x4F5C;&#x4E3A;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x4F20;&#x5165;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isBetween(&apos;2010-01-01&apos;, &apos;2012-01-01&apos;, &apos;year&apos;); // false
moment(&apos;2010-10-20&apos;).isBetween(&apos;2009-12-31&apos;, &apos;2012-01-01&apos;, &apos;year&apos;); // true
</code></pre>
<p>&#x4E0E; <code>moment#isSame</code>&#x3001;<code>moment#isBefore</code>&#x3001;<code>moment#isAfter</code> &#x4E00;&#x6837;&#xFF0C;<code>moment#startOf</code> &#x652F;&#x6301;&#x7684;&#x4EFB;&#x4F55;&#x65F6;&#x95F4;&#x5355;&#x4F4D;&#x4E5F;&#x9002;&#x7528;&#x4E8E; <code>moment#isBetween</code>&#x3002;
&#x5E74;&#x4EFD;&#x3001;&#x6708;&#x4EFD;&#x3001;&#x661F;&#x671F;&#x3001;ISO&#x661F;&#x671F;&#x3001;&#x65E5;&#x671F;&#x3001;&#x5C0F;&#x65F6;&#x3001;&#x5206;&#x949F;&#x3001;&#x79D2;&#x949F;&#x3002;</p>
<p><strong>2.13.0</strong> &#x7248;&#x672C;&#x5F15;&#x5165;&#x4E86;&#x5305;&#x5BB9;&#x6027;&#x3002;
<code>[</code> &#x8868;&#x793A;&#x5305;&#x542B;&#x3002;
<code>(</code> &#x8868;&#x793A;&#x6392;&#x9664;&#x3002;
&#x5982;&#x679C;&#x4F7F;&#x7528;&#x5305;&#x5BB9;&#x6027;&#x53C2;&#x6570;&#xFF0C;&#x5219;&#x5FC5;&#x987B;&#x4F20;&#x5165;&#x4E24;&#x4E2A;&#x6307;&#x793A;&#x7B26;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-10-30&apos;, &apos;2016-12-30&apos;, null, &apos;()&apos;); //false
moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-10-30&apos;, &apos;2016-12-30&apos;, null, &apos;[)&apos;); //true
moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-01-01&apos;, &apos;2016-10-30&apos;, null, &apos;()&apos;); //false
moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-01-01&apos;, &apos;2016-10-30&apos;, null, &apos;(]&apos;); //true
moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-10-30&apos;, &apos;2016-10-30&apos;, null, &apos;[]&apos;); //true
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x5982;&#x679C; <code>from</code> &#x548C; <code>to</code> &#x53C2;&#x6570;&#x76F8;&#x540C;&#xFF0C;&#x4F46;&#x5305;&#x5BB9;&#x6027;&#x53C2;&#x6570;&#x4E0D;&#x540C;&#xFF0C;&#x5219;&#x5C06;&#x4F1A;&#x8FD4;&#x56DE; false&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-10-30&apos;, &apos;2016-10-30&apos;, null, &apos;(]&apos;); //false
</code></pre>
<p>&#x5982;&#x679C;&#x672A;&#x6307;&#x5B9A;&#x5305;&#x5BB9;&#x6027;&#x53C2;&#x6570;&#xFF0C;&#x5219; Moment &#x5C06;&#x4F1A;&#x9ED8;&#x8BA4;&#x4E3A; <code>()</code>&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">//From 2.13.0 onward
moment().isBetween(moment-like, moment-like);
moment().isBetween(moment-like, moment-like, String);
moment().isBetween(moment-like, moment-like, String, String);
// where moment-like is Moment|String|Number|Date|Array

//2.9.0 to 2.12.0
moment().isBetween(moment-like, moment-like);
moment().isBetween(moment-like, moment-like, String);
// where moment-like is Moment|String|Number|Date|Array
</code></pre>

							</div>
<p>Check if a moment is between two other moments, optionally looking at unit
scale (minutes, hours, days, etc).  The match is exclusive. The first two arguments will be parsed as moments, if not already so.</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isBetween(&apos;2010-10-19&apos;, &apos;2010-10-25&apos;); // true
moment(&apos;2010-10-20&apos;).isBetween(&apos;2010-10-19&apos;, undefined); // true, since moment(undefined) evaluates as moment()
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass the units as the third parameter.</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isBetween(&apos;2010-01-01&apos;, &apos;2012-01-01&apos;, &apos;year&apos;); // false
moment(&apos;2010-10-20&apos;).isBetween(&apos;2009-12-31&apos;, &apos;2012-01-01&apos;, &apos;year&apos;); // true
</code></pre>
<p>Like <code>moment#isSame</code>, <code>moment#isBefore</code>, <code>moment#isAfter</code> any of the units of
time that are supported for <code>moment#startOf</code> are supported for
<code>moment#isBetween</code>. Year, month, week, isoWeek, day, hour, minute, and second.</p>
<p>Version <strong>2.13.0</strong> introduces inclusivity. A <code>[</code> indicates inclusion of a value. A <code>(</code> indicates exclusion.
If the inclusivity parameter is used, both indicators must be passed.</p>
<pre><code class="language-javascript">moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-10-30&apos;, &apos;2016-12-30&apos;, null, &apos;()&apos;); //false
moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-10-30&apos;, &apos;2016-12-30&apos;, null, &apos;[)&apos;); //true
moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-01-01&apos;, &apos;2016-10-30&apos;, null, &apos;()&apos;); //false
moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-01-01&apos;, &apos;2016-10-30&apos;, null, &apos;(]&apos;); //true
moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-10-30&apos;, &apos;2016-10-30&apos;, null, &apos;[]&apos;); //true
</code></pre>
<p>Note that in the event that the <code>from</code> and <code>to</code> parameters are the same,
but the inclusivity parameters are different, false will preside.</p>
<pre><code class="language-javascript">moment(&apos;2016-10-30&apos;).isBetween(&apos;2016-10-30&apos;, &apos;2016-10-30&apos;, null, &apos;(]&apos;); //false
</code></pre>
<p>If the inclusivity parameter is not specified, Moment will default to <code>()</code>.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>